Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conversion of a thrown exceptions with unknown error codes #486

Merged
merged 2 commits into from
Feb 3, 2024

Conversation

KLarpen
Copy link
Contributor

@KLarpen KLarpen commented Dec 20, 2023

Notice: custom exceptions with error code less then 500 still be passed as is (neither code not message won't be converted). The basis of the decision — potential necessity to imitate client error responses (400-499).

As a result of this PR:

// Code
throw new Error('Custom exception', 12345);

// Return message
{"type":"callback","id":5,"error":{"message":"Internal Server Error","code":500}}

// Server log distinguishes codes
21:13:35  W2   error   127.0.0.1	GET	/api	500	12345	Error: Custom exception

HOWEVER

// Code
throw new Error('Custom exception', 404);

// Return message contains error text without replacement by known reason phrases of status codes
{"type":"callback","id":4,"error":{"message":"Custom exception","code":404}}

// Server log
21:12:18  W2   error   127.0.0.1	GET	/api	404	404	Error: Custom exception

Closes: #485

  • tests and linter show no problems (npm t)
  • tests are added/updated for bug fixes and new features
  • code is properly formatted (npm run fmt)
  • description of changes is added in CHANGELOG.md
  • update .d.ts typings

Notice: custom exceptions with error code less then 500 still be passed as is (neither code not message won't be converted). The basis of the decision — potential necessity to imitate client error responses (400-499).

Closes: metarhia#485
Copy link
Member

@tshemsedinov tshemsedinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

KLarpen added a commit to KLarpen/Metarhia-Docs that referenced this pull request Dec 22, 2023
@KLarpen
Copy link
Contributor Author

KLarpen commented Dec 26, 2023

I just added proposal to replace hard coded 500 & 599 HTTP error codes with constants (currently only for usage in rules). That's the second version of proposal. We had discussed first version of proposal at Q&A call 55 (it was rejected and I'm agree with that). The commit KLarpen@d6681b0 from branch https://github.com/KLarpen/metacom/tree/replace-http-codes-with-constants contains two separate constants with shorter names than SERVER_ERROR_CODES.min as was in first version.

@tshemsedinov tshemsedinov merged commit fc01e21 into metarhia:master Feb 3, 2024
1 check passed
@KLarpen KLarpen deleted the fix-conversion-of-exceptions branch February 5, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conversion of a thrown exceptions with unknown error codes or 404 not happening
2 participants